package com.xiaochong.bitong.api.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xiaochong.bitong.api.constant.ReturnCode;
import com.xiaochong.service.common.config.oss.OSSTool;
import com.xiaochong.tir.common.data.mapper.SplashMapper;
import com.xiaochong.tir.common.data.po.Splash;
import com.xiaochong.tir.common.data.vo.ApiResultVo;
import com.xiaochong.tir.common.util.ApiResultCodeUtils;

/**
 * @author qzw
 * 2018年9月7日 下午4:13:00
 * @description 
 **/
@Service
public class SplashService {

	@Autowired
	private SplashMapper splashMapper;
	
	@Autowired
	private OSSTool ossTool;
	
	public ApiResultVo<Splash> getSplash(){
		ApiResultVo<Splash> sp = new ApiResultVo<Splash>();
		Splash s = new Splash();
		try{
			s.setEnableFlag(true);
			Splash sh = splashMapper.selectByEntity(s);
			if(sh == null){
				sp.setCode(ReturnCode.DATA_NOT_EXIST);
				sp.setMessage(ApiResultCodeUtils.SYSTEM_NULL.getMsg());
				return sp;
			}
			String imgUrl=ossTool.getOSSUrl( sh.getSplashImg());
			sh.setSplashImg(imgUrl);
			sp.setData(sh);
			sp.setCode(ReturnCode.SUCCESS);
			sp.setMessage(ApiResultCodeUtils.BASE_SUCCESS.getMsg());
		}catch(Throwable t){
			t.printStackTrace();
		}
		return sp;
	}
}
